package com.wss.controller;

import com.wss.domain.*;
import com.wss.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
public class SystemIndexController {

    @Autowired
    private AccountService accountService;
    @Autowired
    private PermissionService permissionService;
    @Autowired
    private VideoService videoService;
    @Autowired
    private VideoTypeService videoTypeService;
    @Autowired
    private BlogService blogService;
    @Autowired
    private BlogTypeService blogTypeService;
    @Autowired
    private CommentService commentService;
    @Autowired
    private OrderService orderService;

    /**
     * 用户主页
     * @param model
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/indexMain")
    public String indexMain(Model model, HttpServletRequest request, HttpServletResponse response) {
        // 查询最新8条视频信息
        List<Video> videoList = videoService.findVideoTop8();
        // 查询最新8条博客信息
        List<Blog> blogList = blogService.findBlogTop8();
        // 查询所有视频分类信息
        List<VideoType> qianduanList = videoTypeService.findVideoTypeByVthid(1);
        List<VideoType> houduanList = videoTypeService.findVideoTypeByVthid(2);
        List<VideoType> shujukuList = videoTypeService.findVideoTypeByVthid(3);
        List<VideoType> wangluoList = videoTypeService.findVideoTypeByVthid(4);
        model.addAttribute("videoList",videoList);
        model.addAttribute("blogList",blogList);
        model.addAttribute("qianduanList",qianduanList);
        model.addAttribute("houduanList",houduanList);
        model.addAttribute("shujukuList",shujukuList);
        model.addAttribute("wangluoList",wangluoList);
        return "indexMain";
    }

    /**
     * 管理员主页
     * @param model
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/indexAdmin")
    public String indexAdmin(Model model, HttpServletRequest request, HttpServletResponse response) {
        // 查询所有用户信息
        List<Account> userList = accountService.findAll();
        // 查询所有权限信息
        List<Permission> permList = permissionService.findAll();
        // 查询所有视频信息
        List<Video> videoList = videoService.findVideoAll();
        // 查询所有视频分类信息
        List<VideoType> videoTypeList = videoTypeService.findTypeAll();
        // 查询所有博客信息
        List<Blog> blogList = blogService.findBlogAll();
        // 查询所有博客分类信息
        List<BlogType> blogTypeList = blogTypeService.findType();
        // 查询所有评论信息
        List<Comment> commentList = commentService.findCommentAll();
        // 查询所有订单信息
        List<Order> orderList = orderService.findOrderAll();
        /**
         * 封装所有列表到model中
         */
        model.addAttribute("userList",userList);
        model.addAttribute("permList",permList);
        model.addAttribute("videoList",videoList);
        model.addAttribute("videoTypeList",videoTypeList);
        model.addAttribute("blogList",blogList);
        model.addAttribute("blogTypeList",blogTypeList);
        model.addAttribute("commentList",commentList);
        model.addAttribute("orderList",orderList);
        return "indexAdmin";
    }

}
